package com.tsing.wms.vo.req;

import com.tsing.wms.valid.AddGroup;
import com.tsing.wms.valid.UpdateGroup;
import com.tsing.wms.valid.ValidList;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Range;

import javax.validation.Valid;
import javax.validation.constraints.*;

/**
 * @author TheTsing
 * @create 2022-04-16 12:25
 */
@Data
public class RecordReqVO {

    @Null(message = "新增时不能传入id", groups = {AddGroup.class})
    @NotBlank(message = "id不能为空", groups = {UpdateGroup.class})
    private String id;

    @ApiModelProperty("出入库仓库id")
    @NotBlank(message = "出入库仓库id不能为空", groups = {AddGroup.class})
    private String storehouseId;

    @ApiModelProperty("操作人员id")
    @NotBlank(message = "操作人员id不能为空", groups = {AddGroup.class})
    private String userId;

    @ApiModelProperty("描述")
    private String description;

    @ApiModelProperty("出库还是入库 0 出库   1 入库")
    @NotNull(message = "类型不能为空", groups = {AddGroup.class})
    @Null(message = "修改时不能传入类型", groups = {UpdateGroup.class})
    @Range(min = 0, max = 1, message = "只能传入0或1，出库还是入库 0 出库   1 入库", groups = {AddGroup.class, UpdateGroup.class})
    private Integer type;

    @Valid
    @ApiModelProperty("出入库清单")
    @NotEmpty(message = "至少包含一个出入库清单", groups = {AddGroup.class, UpdateGroup.class})
    private ValidList<RecordDetailReqVO> recordDetails;

    @Data
    public static class RecordDetailReqVO {

        @ApiModelProperty("货物id")
        @NotBlank(message = "货物id不能为空", groups = {AddGroup.class, UpdateGroup.class})
        private String goodsId;

        @ApiModelProperty("数量")
        @NotNull(message = "数量不能为空", groups = {AddGroup.class, UpdateGroup.class})
        @DecimalMin(value = "1", message = "数量不能小于1", groups = {AddGroup.class, UpdateGroup.class})
        private Integer amount;

    }

}
